package fileio;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class FileIo {
	private File file;
	private PrintWriter writer;
	public FileIo(String fileName) throws IOException{
		//creates a new File with the fileName
		file = new File (fileName);
		if(file.exists()){
			file.delete();
		}
		file.createNewFile();
		writer = new PrintWriter(new FileWriter(file));
	}

	public synchronized void write(String data){	
		//writes the line of data to the file
		if(!writer.checkError()){
			writer.println(data);
			writer.flush();
		}
	}
	public synchronized void close(){
		//closes the writer
		writer.close();
	}

}
